package com.dlnu.shoping.shopping.mapper.provider;

import org.apache.commons.lang.StringUtils;

public class SqlProvider {
    public String queryUserListSql(String username, String nickname){
        String sql = "select * from test_user where 1 = 1";
        if(StringUtils.isNotEmpty(username)){
            sql += " and username like '%" + username + "%' ";
        }
        if(StringUtils.isNotEmpty(nickname)){
            sql += " and nickname like '%" + nickname + "%' ";
        }
        return sql;
    }

    public String addressListSql(int useId){
        String sql = "SELECT a.use_id,u.user_name,a.address,a.phone,a.order_id from address a,user u WHERE u.use_id = a.use_id";
        if(useId != 0) {
            sql += " and a.use_id = " + useId;
        }
        return sql;
    }

    public String cartSelectByUseId(int useId){
        String sql = "select create_time,p.pro_id,p.intro,p.picture,p.price,s.pro_num,s.clothes_size from product_information p,shopping_cart s where p.pro_id = s.pro_id";
        sql += " and use_id = " + useId;
        return sql;
    }

    public String orderSelectByUseId(Integer useId) {
        String sql = "select o.pro_id,p.`name`,o.address_id,o.create_time,p.intro,p.crossed_price,p.price,p.picture\n" +
                "from orderlist o,product_information p where p.pro_id = o.pro_id";
        sql += " and o.user_id = " + useId;
        return sql;
    }

    public String categoryByCid(Integer categoryId) {
        String sql = "SELECT p.`name`,p.price,p.picture,p.intro,p.crossed_price,p.pro_id\n" +
                "from category c, product_information p where c.category_id = p.category_id";
        sql += " and c.category_id = " + categoryId;
        return sql;
    }
}
